﻿#include "mybutton.h"

myButton::myButton(QWidget *parent):QPushButton(parent)
{
    //信号和槽连接起来
    connect(this,&QPushButton::clicked,this,&myButton::dianji);
    connect(this,&myButton::ceshi,this,&myButton::on_myButton_ceshi);
}

void myButton::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    //rect()返回包括这个部件的矩形
    painter.setRenderHint(QPainter::Antialiasing);//抗锯齿
    setFixedSize(QSize(100, 100));//设置按钮长和宽，保证是个圆型
    painter.drawEllipse(rect());
    painter.drawText(rect(), Qt::AlignCenter, this->text());
    //qDebug()<<"子按钮:"<<event;
}

void myButton::dianji()
{
    QString str=this->text();
    emit ceshi(str);
    //qDebug()<<"我是自定义槽";
}

void myButton::on_myButton_ceshi(QString qs)
{
    qDebug()<<"开始测试:"<<qs;
}
